package com.example.contentprovider0216.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.example.contentprovider0216.utils.Constants;

public class UserDatabaseHelper extends SQLiteOpenHelper {
    private static final String TAG = "UserDatabaseHelper";

    public UserDatabaseHelper(@Nullable Context context) {
        super(context, Constants.DB_NAME,null,Constants.DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建数据库
        String createSql="create table "+
                Constants.TABLE_NAME+
                "("+Constants.FIELD_ID+
                " integer primary key autoincrement,"+Constants.FIELD_USER_NAME+
                " text,"+Constants.FIELD_PASSWORD+
                " text,"+Constants.FIELD_SEX+
                " text,"+Constants.FIELD_AGE+
                " integer)";
        db.execSQL(createSql);
        //打印log日志查看数据库是否创建成功
        Log.d(TAG,"oncreate.....");
    }

    /**
     * 数据库升级
     * @param db
     * @param oldVersion 老数据库名称
     * @param newVersion 新数据库名称
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
